//
//  PickerManager.h
//
//
//  Created by ChenJianWei on 16/8/10
//
//

#import "DTPickerManager.h"

#define PickerSCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define PickerSCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#define PickerHeight 200.f
#define ActionHeight 50.f
#define PickerContentRect CGRectMake(0, PickerSCREEN_HEIGHT - PickerHeight, PickerSCREEN_WIDTH, PickerHeight)
#define ActionContentRect CGRectMake(0, PickerSCREEN_HEIGHT - PickerHeight - ActionHeight, PickerSCREEN_WIDTH, ActionHeight)
#define PickerContentBackgroundColor [UIColor whiteColor]

@interface DTPickerManager ()<UIPickerViewDelegate,UIPickerViewDataSource>

@property (strong, nonatomic) UIView *dataPickerContenView;
@property (strong, nonatomic) UIPickerView *pickerView;
@property (strong, nonatomic) UIDatePicker *datePickerView;
@property (strong, nonatomic) UIView *backgroundContentView;
@property (strong, nonatomic) UIView *pickerContentView;
@property (strong, nonatomic) UIView *actionContentView;
@property (copy, nonatomic) PickerManagerConfirmBlock confirmBlock;
@property (copy, nonatomic) PickerManagerCancelBlock cancelBlock;
@property (copy, nonatomic) PickerManagerSlideBlock slideBlock;

@end

static DTPickerManager *sz_picker = nil;

@implementation DTPickerManager

+ (DTPickerManager *)shareManager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sz_picker = [[DTPickerManager alloc]init];
    });
    return sz_picker;
}

- (void)showPickerAndCancel:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self showNoticeString];
    });
    self.confirmBlock = confirmBlock;
    self.cancelBlock = cancelBlock;
    self.backgroundContentView.hidden = NO;
    [self.pickerView reloadAllComponents];
    [[[UIApplication sharedApplication]keyWindow] addSubview:self.backgroundContentView];
    
    self.backgroundContentView.alpha = 0;
    [UIView animateWithDuration:0.0 animations:^{
        self.backgroundContentView.alpha = 1;
    } completion:^(BOOL finished) {
        self.backgroundContentView.alpha = 1;
    }];

}

- (void)showPickerAndCancel:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock andSlideBlock:(PickerManagerSlideBlock)slideBlock
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self showNoticeString];
    });
    self.confirmBlock = confirmBlock;
    self.slideBlock = slideBlock;
    self.cancelBlock = cancelBlock;
    self.backgroundContentView.hidden = NO;
    [self.pickerView reloadAllComponents];
    
    self.backgroundContentView.alpha = 0;
    [UIView animateWithDuration:0.5 animations:^{
        self.backgroundContentView.alpha = 1;
    } completion:^(BOOL finished) {
        self.backgroundContentView.alpha = 1;
    }];
}

- (void)hidePicker
{
    self.backgroundContentView.hidden = YES;
}

- (id)init
{
    if ([super init]) {
        [self setBaseViewForPicker];
    }
    return self;
}

- (void)setBaseViewForPicker
{
    [self backgroundContentView];
    [self pickerContentView];
    [self dataPickerContenView];
    [self actionContentView];
}

- (void)showNoticeString
{
    if (self.noticeArray.count == 0) {
        return;
    }
    for (int i = 0; i < self.dataArray.count; i++) {
        
        UIView *view = [self.pickerView viewForRow:1 forComponent:i];
        if (view == nil){
            view = [self.pickerView viewForRow:0 forComponent:i];
        }
        int component = i;
        if (![self.pickerContentView viewWithTag:(100 + component)]) {
            if (self.noticeArray.count != 0) {
                NSString *contentString = [[[view subviews]firstObject]text];
                NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:20],NSFontAttributeName,nil];
                CGFloat width = [contentString boundingRectWithSize:CGSizeMake(100, 20) options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size.width;
                CGRect powerRect=[view convertRect:view.frame toView:self.pickerContentView];
                UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(powerRect) + 5 + CGRectGetWidth(powerRect)/2 + width/2, self.pickerView.center.y - 10, 40, 20)];
                label.tag = (100 + component);
                label.text = self.noticeArray[component];
                label.textColor = [UIColor blackColor];
                label.font = [UIFont systemFontOfSize:15.f];
                [self.pickerContentView addSubview:label];
                
                label.alpha = 0;
                [UIView animateWithDuration:0.2 animations:^{
                    label.alpha = 1;
                } completion:^(BOOL finished) {
                    label.alpha = 1;
                }];
            }
        }else{
            UILabel *label = [self.pickerContentView viewWithTag:(100 + component)];
            
            if (self.dataArray.count > component) {
                label = self.noticeArray[component];
            }else{
                label.text = @"";
            }
        }
    }
}

- (UIView *)backgroundContentView
{
    if (!_backgroundContentView) {
        _backgroundContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, PickerSCREEN_WIDTH, PickerSCREEN_HEIGHT)];
        [[[UIApplication sharedApplication]keyWindow] addSubview:_backgroundContentView];
        _backgroundContentView.hidden = YES;
        _backgroundContentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    }
    return _backgroundContentView;
}

- (UIView *)pickerContentView
{
    if (!_pickerContentView) {
        _pickerContentView = [[UIView alloc]initWithFrame:PickerContentRect];
        [self.backgroundContentView addSubview:_pickerContentView];
        _pickerContentView.backgroundColor = PickerContentBackgroundColor;
        [_pickerContentView addSubview:self.pickerView];
    }
    return _pickerContentView;
}

- (UIView *)dataPickerContenView
{
    if (!_dataPickerContenView) {
        _dataPickerContenView = [[UIView alloc]initWithFrame:PickerContentRect];
        [self.backgroundContentView addSubview:_dataPickerContenView];
        _dataPickerContenView.backgroundColor = PickerContentBackgroundColor;
        _dataPickerContenView.hidden = YES;
        [_dataPickerContenView addSubview:self.datePickerView];
    }
    return _dataPickerContenView;
}

- (UIPickerView *)pickerView
{
    if (!_pickerView) {
        _pickerView = [[UIPickerView alloc]initWithFrame:self.pickerContentView.bounds];
        _pickerView.delegate = self;
        _pickerView.dataSource = self;
    }
    return _pickerView;
}

- (UIDatePicker *)datePickerView
{
    if (!_datePickerView) {
        _datePickerView = [[UIDatePicker alloc]initWithFrame:self.dataPickerContenView.bounds];
        _datePickerView.datePickerMode = UIDatePickerModeDate;
        _datePickerView.maximumDate = [NSDate date];
    }
    return _datePickerView;
}


- (UIView *)actionContentView
{
    if (!_actionContentView) {
        _actionContentView = [[UIView alloc]initWithFrame:ActionContentRect];
        [self.backgroundContentView addSubview:_actionContentView];
        _actionContentView.backgroundColor = PickerContentBackgroundColor;
        
        UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
        [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
        [leftBtn setTitleColor:rgba(63,147,232,1) forState:UIControlStateNormal];
        [leftBtn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        leftBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_actionContentView addSubview:leftBtn];
        
        UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetWidth(_actionContentView.frame) - leftBtn.frame.size.width, leftBtn.frame.origin.y, leftBtn.frame.size.width, leftBtn.frame.size.height)];
        [rightBtn setTitle:@"确定" forState:UIControlStateNormal];
        [rightBtn setTitleColor:rgba(63,147,232,1) forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        rightBtn.titleLabel.font = leftBtn.titleLabel.font;
        [_actionContentView addSubview:rightBtn];
        
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(_actionContentView.frame) - 1, CGRectGetWidth(_actionContentView.frame), 0.6)];
        line.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.15];
        [_actionContentView addSubview:line];
    }
    return _actionContentView;
}

#pragma mark - <UIPickerViewDelegate,UIPickerViewDataSource>
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return self.dataArray.count;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [self.dataArray[component]count];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    if (!view){
        view = [[UIView alloc]init];
    }
    UILabel *text = [[UILabel alloc]init];
    if (self.isFullScreen == 1) {
        text.frame = CGRectMake(0, 0, PickerSCREEN_WIDTH, 50);
    } else {
        text.frame = CGRectMake(0, 0, PickerSCREEN_WIDTH/(self.dataArray.count + 1), 50);
    }

    text.font = [UIFont systemFontOfSize:20];
    text.textAlignment = NSTextAlignmentCenter;
    text.text = self.dataArray[component][row];
    text.tag = 10;
    
    [view addSubview:text];

    return view;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.dataArray[component][row];
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 50;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    if (self.isFullScreen == 1) {
        return PickerSCREEN_WIDTH;
    } else {
        return PickerSCREEN_WIDTH/(self.dataArray.count + 1);
    }
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.dataArray.count; i ++) {
        [arr addObject:@([self.pickerView selectedRowInComponent:i])];
    }
    
    if (self.slideBlock) {
        self.slideBlock(arr);
    }
}

- (void)leftBtnClick:(UIButton *)sender
{
    [self.backgroundContentView removeFromSuperview];
    
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.dataArray.count; i ++) {
        [arr addObject:@([self.pickerView selectedRowInComponent:i])];
    }
    if (self.cancelBlock) {
        self.cancelBlock(arr);
    }
    self.backgroundContentView.hidden = YES;
    
    for (UIView *view in self.pickerContentView.subviews) {
        if ([view isEqual:self.pickerView]) {
            continue;
        }
        [view removeFromSuperview];
    }
    [self.pickerView reloadAllComponents];
    
    for (int i = 0; i < self.dataArray.count; i++) {
        [self.pickerView selectRow:0 inComponent:i animated:YES];
    }
}

- (void)rightBtnClick:(UIButton *)sender
{
    [self.backgroundContentView removeFromSuperview];
    
    NSMutableArray *arr = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.dataArray.count; i ++) {
        [arr addObject:@([self.pickerView selectedRowInComponent:i])];
    }
    if (self.confirmBlock) {
        self.confirmBlock(arr);
    }
    self.backgroundContentView.hidden = YES;
    
    for (UIView *view in self.pickerContentView.subviews) {
        if ([view isEqual:self.pickerView]) {
            continue;
        }
        [view removeFromSuperview];
    }
    [self.pickerView reloadAllComponents];
    for (int i = 0; i < self.dataArray.count; i++) {
        [self.pickerView selectRow:0 inComponent:i animated:YES];
    }
}

- (void)showLocationByValue:(NSArray *)valueList
{
    for (int i = 0; i < self.dataArray.count; i ++) {
        NSArray *comList = self.dataArray[i];
        for (int j = 0; j < comList.count ;j++) {
            if ([valueList[i] isEqualToString:comList[j]]){
                [self.pickerView selectRow:j inComponent:i animated:YES];
            }
        }
    }
}

- (void)showLocationByDate:(NSDate *)date
{
    [self.datePickerView setDate:date animated:YES];
}


#pragma mark - 用例
#pragma mark - 生日
- (void)showDate:(NSDate *)date pickerWithBirthDayAndPicker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    self.pickerContentView.hidden = YES;
    self.dataPickerContenView.hidden = NO;
    if (date) {
        self.datePickerView.date = date;
    }
    self.datePickerView.datePickerMode = UIDatePickerModeDate;
    self.datePickerView.maximumDate = [NSDate date];
    self.datePickerView.minimumDate  = nil;
    
    
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        self.pickerContentView.hidden = NO;
        self.dataPickerContenView.hidden = YES;
        
        NSDate *currentDate = self.datePickerView.date;
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy MM dd"];
        [formatter setTimeZone:[NSTimeZone systemTimeZone]];
        [formatter setLocale:[NSLocale autoupdatingCurrentLocale]];
        NSString *valueString = [formatter stringFromDate:currentDate];
        
        NSArray *value = [valueString componentsSeparatedByString:@" "];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        self.pickerContentView.hidden = NO;
        self.dataPickerContenView.hidden = YES;
        
        NSDate *currentDate = self.datePickerView.date;
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy MM dd"];
        [formatter setTimeZone:[NSTimeZone systemTimeZone]];
        [formatter setLocale:[NSLocale autoupdatingCurrentLocale]];
        NSString *valueString = [formatter stringFromDate:currentDate];
        
        NSArray *value = [valueString componentsSeparatedByString:@" "];
        
        if (cancelBlock) {
            confirmBlock(value);
        }
    }];
}

#pragma mark - 预约日期
- (void)showDate:(NSDate *)date pickerWithFutureDateAndPicker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    self.pickerContentView.hidden = YES;
    self.dataPickerContenView.hidden = NO;
    if (date) {
        self.datePickerView.date = date;
    }
    self.datePickerView.datePickerMode = UIDatePickerModeDate;
    self.datePickerView.maximumDate = nil;
    self.datePickerView.minimumDate = [NSDate date];
    
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        self.pickerContentView.hidden = NO;
        self.dataPickerContenView.hidden = YES;
        
        NSDate *currentDate = self.datePickerView.date;
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy MM dd"];
        [formatter setTimeZone:[NSTimeZone systemTimeZone]];
        [formatter setLocale:[NSLocale autoupdatingCurrentLocale]];
        NSString *valueString = [formatter stringFromDate:currentDate];
        
        NSArray *value = [valueString componentsSeparatedByString:@" "];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        self.pickerContentView.hidden = NO;
        self.dataPickerContenView.hidden = YES;
        
        NSDate *currentDate = self.datePickerView.date;
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy MM dd"];
        [formatter setTimeZone:[NSTimeZone systemTimeZone]];
        [formatter setLocale:[NSLocale autoupdatingCurrentLocale]];
        NSString *valueString = [formatter stringFromDate:currentDate];
        
        NSArray *value = [valueString componentsSeparatedByString:@" "];
        
        if (cancelBlock) {
            confirmBlock(value);
        }
    }];
}

#pragma mark - 预约时间
- (void)showDate:(NSDate *)date pickerWithTimeAndPicker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock{
    self.pickerContentView.hidden = YES;
    self.dataPickerContenView.hidden = NO;
    if (date) {
        self.datePickerView.date = date;
    }
    self.datePickerView.maximumDate = nil;
    self.datePickerView.minimumDate = nil;
//    self.datePickerView.minimumDate = [NSDate date];
    self.datePickerView.datePickerMode = UIDatePickerModeTime;
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        self.pickerContentView.hidden = NO;
        self.dataPickerContenView.hidden = YES;
        
        NSDate *currentDate = self.datePickerView.date;
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.AMSymbol = @"上午";
        formatter.PMSymbol = @"下午";
        [formatter setDateFormat:@"aaa hh mm"];
        [formatter setTimeZone:[NSTimeZone systemTimeZone]];
        [formatter setLocale:[NSLocale autoupdatingCurrentLocale]];
        NSString *valueString = [formatter stringFromDate:currentDate];
        
        NSArray *value = [valueString componentsSeparatedByString:@" "];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        self.pickerContentView.hidden = NO;
        self.dataPickerContenView.hidden = YES;
        
        NSDate *currentDate = self.datePickerView.date;
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.AMSymbol = @"上午";
        formatter.PMSymbol = @"下午";
        [formatter setDateFormat:@"aaa hh mm"];
        [formatter setTimeZone:[NSTimeZone systemTimeZone]];
        [formatter setLocale:[NSLocale autoupdatingCurrentLocale]];
        NSString *valueString = [formatter stringFromDate:currentDate];
        
        NSArray *array = [valueString componentsSeparatedByString:@" "];
        NSString *hourValue = @"";
        NSString *secondValue = @"";
        if (array.count == 3)
        {
            if ([array[0] isEqualToString:@"下午"])
            {
                hourValue = [NSString stringWithFormat:@"%i",[array[1] intValue] + 12];
                secondValue = array[2];
            }
        }
        else if (array.count == 2)
        {
            hourValue = array[0];
            secondValue = array[1];
        }
        
        if (cancelBlock) {
            confirmBlock(@[hourValue,secondValue]);
        }
    }];
}

- (void)showPickerWithWeightAndPicker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    NSMutableArray *weight = [[NSMutableArray alloc]init];
    for (int i = 249; i >= 30; i--) {
        [weight addObject:@(i).stringValue];
    }
    
    [DTPickerManager shareManager].noticeArray = @[@"Kg"];
    [DTPickerManager shareManager].dataArray = @[weight];
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            confirmBlock(value);
        }
    }];
    
    [[DTPickerManager shareManager]showLocationByValue:@[@"50"]];
}

-(void)showPickerWithHeightAndPicker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    NSMutableArray *weight = [[NSMutableArray alloc]init];
    for (int i = 244; i >= 80; i--) {
        [weight addObject:@(i).stringValue];
    }
    
    [DTPickerManager shareManager].noticeArray = @[@"cm"];
    [DTPickerManager shareManager].dataArray = @[weight];
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            confirmBlock(value);
        }
    }];
    
    [[DTPickerManager shareManager]showLocationByValue:@[@"170"]];
}

- (void)showPickerWithSexAndPicker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    NSMutableArray *weight = [[NSMutableArray alloc]initWithArray:@[@"女",@"男"]];
    
    [DTPickerManager shareManager].dataArray = @[weight];
    [DTPickerManager shareManager].noticeArray = @[];
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            confirmBlock(value);
        }
    }];
}

- (void)showPickerWithAfterSalesTypeAndPicker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    NSMutableArray *weight = [[NSMutableArray alloc]initWithArray:@[@"移动",@"换滤芯",@"故障报修"]];
    
    [DTPickerManager shareManager].dataArray = @[weight];
    [DTPickerManager shareManager].noticeArray = @[];
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            confirmBlock(value);
        }
    }];
}


- (void)showPickerWithMax:(int)max min:(int)min notice:(NSString *)notice picker:(PickerManagerCancelBlock)cancelBlock andConfirm:(PickerManagerConfirmBlock)confirmBlock
{
    NSMutableArray *weight = [[NSMutableArray alloc]init];
    for (int i = max; i >= min; i--) {
        [weight addObject:@(max - i + min).stringValue];
    }
    
    [DTPickerManager shareManager].noticeArray = @[notice];
    [DTPickerManager shareManager].dataArray = @[weight];
    [[DTPickerManager shareManager]showPickerAndCancel:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            cancelBlock(value);
        }
    } andConfirm:^(NSArray *arr) {
        NSMutableArray *value = [[NSMutableArray alloc]init];
        [value addObject:weight[[arr[0]intValue]]];
        
        if (cancelBlock) {
            confirmBlock(value);
        }
    }];
}
@end
